package Underworld_Survival;

import java.util.*;


public abstract class Armor extends Equipment {
    protected transient String armorEffectId;//应用该防具时唯一效果id
    protected transient Map<AttributeType,EffectValue> onEquip;//应用防具时的具体效果
    protected transient Map<AttributeType,EffectValue> reverse;//移除防具时的效果
    protected transient EffectManager manager;//记录防具效果，用于正确移除
    protected transient EquipmentEffect effect;//防具普通的加成

    public Armor(EffectManager manager) {this.manager = manager;}
    public Armor(EffectManager manager, EquipmentEffect effect){
        this.manager = manager;
        this.effect = effect;}
    public Armor(String name, String introduction, String itemEffect, CurrencyType purchaseCurrency,
                  int priceOfPurchase, int priceOfSelling, Map<AttributeType, EffectValue> onEquipEffect){
        super(name,introduction,itemEffect,purchaseCurrency,priceOfPurchase,priceOfSelling);
        this.armorEffectId = UUID.randomUUID().toString()+"防具";
        this.onEquip=new HashMap<>(onEquipEffect);// 复制传入的效果数据
        this.reverse=new HashMap<>();
        this.effect=new EquipmentEffect(
                role -> {equip(role);},
                role -> {unequip(role);}
        );
    }

    public void equip(Role role) {
        // 注册效果并自动绑定到装备实例
        this.manager=role.getEffectManager();
        String effectId = manager.applyEffect(armorEffectId, onEquip);
        Map<AttributeType, Float> actualValues = manager.getEffectsById(effectId,role);
        role.modifyAttributes(actualValues,true);
    }
    public void unequip(Role role) {
        Map<AttributeType, Float> reverse = manager.removeEffects(armorEffectId,role);
        role.modifyAttributes(reverse,false);
    }

    public Map<AttributeType,EffectValue> getOnEquip(){
        return onEquip;
    }


}

//<木甲>woodenArmor
class woodenArmor extends Armor{
    public woodenArmor() {
        super("<木甲>", "木制的护甲，有一定的防具效果，但穿起来不舒服",
                "防御+4  速度-1", CurrencyType.GOLD, 100, 50,
                // 直接传入预定义的效果数据
                Map.of(AttributeType.BONUS_DEF, new FixedValue(4f),AttributeType.BONUS_EP,new FixedValue(-1f))
        );
        armorEffectId="木甲"+armorEffectId;
    }

    @Override
    public String getItemId() { return "armor_woodenArmor"; }

}
//<锁链甲>chainMail
class chainMail extends Armor{
    public chainMail() {
        super("<锁链甲>", "锁链打造的特殊盔甲",
                "防御+7", CurrencyType.GOLD, 220, 110,
                // 直接传入预定义的效果数据
                Map.of(AttributeType.BONUS_DEF, new FixedValue(7f))
        );
        armorEffectId="锁链甲"+armorEffectId;
    }

    @Override
    public String getItemId() { return "armor_chainMail"; }

}
//<荆棘铁甲>thornyIron
class thornyIron extends Armor{
    public thornyIron() {
        super("<荆棘铁甲>", "无惧前路刀光剑影，反噬锋芒",
                "防御+12  被攻击时反弹伤害", CurrencyType.DIAMOND, 90, 180,
                // 直接传入预定义的效果数据
                Map.of(AttributeType.BONUS_DEF, new FixedValue(12f))
        );
        armorEffectId="荆棘铁甲"+armorEffectId;
        addSpecialEffect(new DamageReflectionEffect(1f));//荆棘铁甲特殊效果，回棘

    }

    @Override
    public String getItemId() { return "armor_thornyIron"; }

}
//<爆裂甲>crackedNail
class crackedNail extends Armor{
    public crackedNail() {
        super("<爆裂甲>", "钢铁之躯里，跳动着狂战士的心脏",
                "防御+7 暴击率+15% 暴击效果+20%", CurrencyType.DIAMOND, 70, 140,
                // 直接传入预定义的效果数据
                Map.of(AttributeType.BONUS_DEF, new FixedValue(7f),AttributeType.BONUS_CRITRATE,new FixedValue(0.15f),
                AttributeType.BONUS_CRITMULTIPLIER,new FixedValue(0.2f))
        );
        armorEffectId="爆裂甲"+armorEffectId;
    }

    @Override
    public String getItemId() { return "armor_crackedNail"; }

}